# Copyright (c) 2024 Contributors to the Eclipse Foundation
#
# See the NOTICE file(s) distributed with this work for additional
# information regarding copyright ownership.
#
# This program and the accompanying materials are made available under the
# terms of the Apache Software License 2.0 which is available at
# https://www.apache.org/licenses/LICENSE-2.0, or the MIT license
# which is available at https://opensource.org/licenses/MIT.
#
# SPDX-License-Identifier: Apache-2.0 OR MIT

package(default_visibility = ["//visibility:public"])

load("@bazel_skylib//lib:selects.bzl", "selects")
load("@bazel_skylib//rules:common_settings.bzl", "string_flag")

exports_files([
    "LICENSE-APACHE",
    "LICENSE-MIT",
])

#
# Config & Platform support
#

config_setting(
    name = "linux",
    constraint_values = ["@platforms//os:linux"],
)

config_setting(
    name = "win-gcc",
    constraint_values = ["@platforms//os:windows"],
    flag_values = {"@bazel_tools//tools/cpp:compiler": "mingw-gcc"},
)

config_setting(
    name = "win-msvc",
    constraint_values = ["@platforms//os:windows"],
    flag_values = {"@bazel_tools//tools/cpp:compiler": "msvc-cl"},
)

#
# Rust Feature Flags
#

string_flag(
    name = "feature_dev_permissions",
    build_setting_default = "auto",
    visibility = ["//visibility:public"],
)
config_setting(
    name = "dev_permissions_auto",
    flag_values = {
        "//:feature_dev_permissions": "auto",
    },
)
config_setting(
    name = "dev_permissions_enabled",
    flag_values = {
        "//:feature_dev_permissions": "on",
    },
)
# NOTE: while this seems superfluous, it is the pattern for cases where *_auto is on by default;
#       therefore this target is introduced to keep all feature flags consistent
selects.config_setting_group(
    name = "cfg_feature_dev_permissions",
    match_any = [
        "//:dev_permissions_enabled",
    ],
)

string_flag(
    name = "feature_logger_log",
    build_setting_default = "auto",
    visibility = ["//visibility:public"],
)
config_setting(
    name = "logger_log_auto",
    flag_values = {
        "//:feature_logger_log": "auto",
    },
)
config_setting(
    name = "logger_log_enabled",
    flag_values = {
        "//:feature_logger_log": "on",
    },
)
# NOTE: while this seems superfluous, it is the pattern for cases where *_auto is on by default;
#       therefore this target is introduced to keep all feature flags consistent
selects.config_setting_group(
    name = "cfg_feature_logger_log",
    match_any = [
        ":logger_log_enabled",
    ],
)

string_flag(
    name = "feature_logger_tracing",
    build_setting_default = "auto",
    visibility = ["//visibility:public"],
)
config_setting(
    name = "logger_tracing_auto",
    flag_values = {
        "//:feature_logger_tracing": "auto",
    },
)
config_setting(
    name = "logger_tracing_enabled",
    flag_values = {
        "//:feature_logger_tracing": "on",
    },
)
# NOTE: while this seems superfluous, it is the pattern for cases where *_auto is on by default;
#       therefore this target is introduced to keep all feature flags consistent
selects.config_setting_group(
    name = "cfg_feature_logger_tracing",
    match_any = [
        ":logger_tracing_enabled",
    ],
)

#
# Alias
#

alias(
    name = "iceoryx2",
    actual = "//iceoryx2:iceoryx2",
    visibility = ["//visibility:public"],
)

alias(
    name = "iceoryx2-c-shared",
    actual = "//iceoryx2-ffi/c:iceoryx2-c-shared",
    visibility = ["//visibility:public"],
)

alias(
    name = "iceoryx2-c-static",
    actual = "//iceoryx2-ffi/c:iceoryx2-c-static",
    visibility = ["//visibility:public"],
)

alias(
    name = "iceoryx2-cxx-shared",
    actual = "//iceoryx2-ffi/cxx:iceoryx2-cxx-shared",
    visibility = ["//visibility:public"],
)

alias(
    name = "iceoryx2-cxx-static",
    actual = "//iceoryx2-ffi/cxx:iceoryx2-cxx-static",
    visibility = ["//visibility:public"],
)

#
# all_srcs
#

filegroup(
    name = "all_srcs",
    srcs = glob([
        "config/**",
        "examples/**",
        "*.bazel",
        "*.lock",
        "*.toml",
        "*.txt",
        "*.md",
        "LICENSE-*",
    ]) + [
        "//benchmarks/event:all_srcs",
        "//benchmarks/publish-subscribe:all_srcs",
        "//benchmarks/queue:all_srcs",
        "//benchmarks/request-response:all_srcs",
        "//iceoryx2-tunnels/end-to-end-testing:all_srcs",
        "//iceoryx2-tunnels/zenoh:all_srcs",
        "//iceoryx2-services/discovery:all_srcs",
        "//iceoryx2:all_srcs",
        "//iceoryx2-bb/container:all_srcs",
        "//iceoryx2-bb/derive-macros:all_srcs",
        "//iceoryx2-bb/elementary:all_srcs",
        "//iceoryx2-bb/elementary-traits:all_srcs",
        "//iceoryx2-bb/lock-free:all_srcs",
        "//iceoryx2-bb/log:all_srcs",
        "//iceoryx2-bb/memory:all_srcs",
        "//iceoryx2-bb/posix:all_srcs",
        "//iceoryx2-bb/system-types:all_srcs",
        "//iceoryx2-bb/testing:all_srcs",
        "//iceoryx2-bb/threadsafe:all_srcs",
        "//iceoryx2-bb/trait-tests:all_srcs",
        "//iceoryx2-cal:all_srcs",
        "//iceoryx2-cli:all_srcs",
        "//iceoryx2-ffi/ffi:all_srcs",
        "//iceoryx2-ffi/c:all_srcs",
        "//iceoryx2-ffi/cxx:all_srcs",
        "//iceoryx2-ffi/ffi-macros:all_srcs",
        "//iceoryx2-ffi/python:all_srcs",
        "//iceoryx2-pal/concurrency-sync:all_srcs",
        "//iceoryx2-pal/configuration:all_srcs",
        "//iceoryx2-pal/posix:all_srcs",
        "//iceoryx2-pal/testing:all_srcs",
    ],
    visibility = ["//visibility:public"],
)
